package com.test.user;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.sound.midi.VoiceStatus;

import com.google.gson.Gson;
import com.test.database.UserCollection;

/**
 * Servlet implementation class UserLogin
 */
@WebServlet("/UserLogin")
public class UserLogin extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public UserLogin() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub	
		
//		// gson使用 http://blog.csdn.net/yang786654260/article/details/44097089
//		// json查看 http://www.json.cn/
//		// 暴风魔镜抓包地址http://res.static.mojing.cn/160630-1-1-1/android/zh/1/page/443513.js
		
//		Gson gson = new Gson();
//
////		response.setCharacterEncoding("UTF-8");
////		response.setContentType("text/plain; charset=utf-8");
//		
//		// 获取数据:http://res.static.mojing.cn/160630-1-1-1/android/zh/1/page/443513.js
//		String jsonData = WebDataCatcher.getData("http://res.static.mojing.cn/160630-1-1-1/android/zh/1/page/443513.js");
//		
//		// 解析数据
//		BaofengJsonObj baofen = gson.fromJson(jsonData, BaofengJsonObj.class);
//		
//		// 返回json数据给浏览器端
//		String ret = gson.toJson(baofen);
//		out.println("status:"+baofen.status+" status_msg:"+baofen.status_msg+" contents:"+baofen.data.landscape_url.contents);
		
		
		if (request.getParameter("fun").equals("GetUserCount")){
			response.setCharacterEncoding("UTF-8");
			response.setContentType("text/plain; charset=utf-8");
			PrintWriter out  = response.getWriter();
			Gson gson = new Gson();
			String ret = gson.toJson(10);
			out.write(ret);
		}
		

		if (request.getParameter("fun").equals("getUserCollection")){
			String ret = new UserCollection().getUserCollection("111");
			response.setCharacterEncoding("UTF-8");
			response.setContentType("text/plain; charset=utf-8");
			PrintWriter out  = response.getWriter();
			out.write(ret);
		}
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
